package com.itboye.ihomebank.activity.finance.fragment;

import android.annotation.SuppressLint;

import com.itboye.ihomebank.R;
import com.itboye.ihomebank.adapter.jinrong.TouZiJiLuAdapter;
import com.itboye.ihomebank.base.BaseFragment;
import com.itboye.ihomebank.bean.ResultEntity;
import com.itboye.ihomebank.bean.TouZiJiLuBean;
import com.itboye.ihomebank.custom.MyListView;
import com.itboye.ihomebank.presenter.JinRongPresenter;
import com.itboye.ihomebank.util.ByAlert;

import java.util.ArrayList;
import java.util.List;
import java.util.Observable;
import java.util.Observer;

/**
 * 投标记录
 */
@SuppressLint("ValidFragment")
public class JiLuActivity extends BaseFragment implements Observer {

    MyListView listView;

    TouZiJiLuAdapter adapter;

    JinRongPresenter presenter;
    String id;

    public JiLuActivity(String id){
        this.id=id;
    }

    @Override
    public int initView() {
        return R.layout.activity_ji_lu;
    }

    @Override
    public void onMyActivityCreated() {
        presenter=new JinRongPresenter(this);
        presenter.touZiJiLu(id);
    }

    @Override
    public void update(Observable observable, Object data) {
        ResultEntity entity = handlerError(data);
        if (entity != null) {
            if (entity.getEventType() == JinRongPresenter.touzi_jilu_success) {
                TouZiJiLuBean bean= (TouZiJiLuBean) entity.getData();
                List<TouZiJiLuBean.A> listBean=new ArrayList<TouZiJiLuBean.A>();
                if (bean.getList().size()>0){
                    listBean.addAll(bean.getList());
                    adapter = new TouZiJiLuAdapter(getActivity(), listBean,
                            R.layout.item_toubiaojilu);
                    listView.setAdapter(adapter);
                }
            }
            if (entity.getEventType()==JinRongPresenter.touzi_jilu_fail){
                ByAlert.alert(entity.getData());
            }
        }
        try {
            closeProgressDialog();
        } catch (Exception e) {
        }
    }
}
